//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "YYUKRPIr.h"
using namespace Cephei::QL::Indexes::Inflation;
#include <gen/QL/Termstructures/YoYInflationTermStructure.h>
#include <gen/QL/Indexes/Region.h>
#include <gen/QL/Times/Period.h>
#include <gen/QL/Currency.h>
#include <gen/QL/Indexes/YoYInflationIndex.h>
#include <gen/QL/Times/Calendar.h>
using namespace Cephei::QL::Termstructures;
using namespace Cephei::QL::Indexes;
using namespace Cephei::QL::Times;
using namespace Cephei::QL;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Indexes::Inflation::CYYUKRPIr::CYYUKRPIr (Boolean interpolated, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Termstructures::IYoYInflationTermStructure^>^ ts) : CYoYInflationIndex(CYYUKRPIr::typeid)
{
    CYoYInflationTermStructure^ _Cts;
    try
    {
#ifdef HANDLE
        _phYYUKRPIr = NULL;
#endif
        bool _interpolated = (bool)ValueHelper::Convert (interpolated);
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Termstructures::IYoYInflationTermStructure^>::IsSome::get (ts))
        {
            _Cts = safe_cast<CYoYInflationTermStructure^> (ts->Value);
            _Cts->Lock();
        }
        Handle<QuantLib::YoYInflationTermStructure>& _ts = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Termstructures::IYoYInflationTermStructure^>::IsSome::get (ts) ? static_cast<Handle<QuantLib::YoYInflationTermStructure>&> (_Cts->GetHandle ()) : Handle<QuantLib::YoYInflationTermStructure>()); //1
        _ppYYUKRPIr = new boost::shared_ptr<QuantLib::YYUKRPIr> (new QuantLib::YYUKRPIr ( _interpolated,  _ts ));
        SetYoYInflationIndex (boost::dynamic_pointer_cast<QuantLib::YoYInflationIndex> (*_ppYYUKRPIr));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
        if (_Cts != nullptr) _Cts->Unlock();
    }
}
Cephei::QL::Indexes::Inflation::CYYUKRPIr::CYYUKRPIr (boost::shared_ptr<QuantLib::YYUKRPIr>& childNative, Object^ owner) : CYoYInflationIndex(CYYUKRPIr::typeid)
{
#ifdef HANDLE
	_phYYUKRPIr = NULL;
#endif
	_ppYYUKRPIr = &childNative;
    _ppYoYInflationIndex = new boost::shared_ptr<QuantLib::YoYInflationIndex> (boost::dynamic_pointer_cast<QuantLib::YoYInflationIndex> (*_ppYYUKRPIr));
}
Cephei::QL::Indexes::Inflation::CYYUKRPIr::CYYUKRPIr (QuantLib::YYUKRPIr& childNative, Object^ owner) : CYoYInflationIndex(CYYUKRPIr::typeid)
{
#ifdef HANDLE
	_phYYUKRPIr = NULL;
#endif
	_ppYYUKRPIr = new boost::shared_ptr<QuantLib::YYUKRPIr> (&childNative);
    _ppYoYInflationIndex = new boost::shared_ptr<QuantLib::YoYInflationIndex> (boost::dynamic_pointer_cast<QuantLib::YoYInflationIndex> (*_ppYYUKRPIr));
    _YYUKRPIrOwner = owner;
    _YoYInflationIndexOwner = owner;
}

Cephei::QL::Indexes::Inflation::CYYUKRPIr::CYYUKRPIr (CYYUKRPIr^ copy) : CYoYInflationIndex(CYYUKRPIr::typeid)
{
#ifdef HANDLE
	_phYYUKRPIr = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppYYUKRPIr = new boost::shared_ptr<QuantLib::YYUKRPIr> (copy->GetShared());
        _ppYoYInflationIndex = new boost::shared_ptr<QuantLib::YoYInflationIndex> (boost::dynamic_pointer_cast<QuantLib::YoYInflationIndex> (*_ppYYUKRPIr));
    }
}
Cephei::QL::Indexes::Inflation::CYYUKRPIr::CYYUKRPIr (System::Type^ t) : CYoYInflationIndex(CYYUKRPIr::typeid)
{
#ifdef HANDLE
	_phYYUKRPIr = NULL;
#endif
	if (!t->IsSubclassOf(CYYUKRPIr::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Indexes::Inflation::CYYUKRPIr::CYYUKRPIr (QuantLib::Handle<QuantLib::YYUKRPIr>& childNative, Object^ owner)  : CYoYInflationIndex(CYYUKRPIr::typeid)
{
	_phYYUKRPIr = &childNative;
	_ppYYUKRPIr = &static_cast<boost::shared_ptr<QuantLib::YYUKRPIr>>(childNative.currentLink());
    _ppYoYInflationIndex = new boost::shared_ptr<QuantLib::YoYInflationIndex> (boost::dynamic_pointer_cast<QuantLib::YoYInflationIndex> (*_ppYYUKRPIr));
    _YYUKRPIrOwner = owner;
}
Cephei::QL::Indexes::Inflation::CYYUKRPIr::CYYUKRPIr (QuantLib::Handle<QuantLib::YYUKRPIr> childNative)  : CYoYInflationIndex(CYYUKRPIr::typeid)
{
	_phYYUKRPIr = &childNative;
	_ppYYUKRPIr = &static_cast<boost::shared_ptr<QuantLib::YYUKRPIr>>(childNative.currentLink());
    _ppYoYInflationIndex = new boost::shared_ptr<QuantLib::YoYInflationIndex> (boost::dynamic_pointer_cast<QuantLib::YoYInflationIndex> (*_ppYYUKRPIr));
}
#endif
#ifdef STRUCT
Cephei::QL::Indexes::Inflation::CYYUKRPIr::CYYUKRPIr (QuantLib::YYUKRPIr childNative)  : CYoYInflationIndex(CYYUKRPIr::typeid)
{
#ifdef HANDLE
	_phYYUKRPIr = NULL;
#endif
	_ppYYUKRPIr = new boost::shared_ptr<QuantLib::YYUKRPIr> (new QuantLib::YYUKRPIr (childNative));
    _ppYoYInflationIndex = new boost::shared_ptr<QuantLib::YoYInflationIndex> (boost::dynamic_pointer_cast<QuantLib::YoYInflationIndex> (*_ppYYUKRPIr));
}
#endif

Cephei::QL::Indexes::Inflation::CYYUKRPIr::~CYYUKRPIr ()
{
    if (_ppYYUKRPIr != NULL)
    {
	    delete _ppYYUKRPIr;
        _ppYYUKRPIr = NULL;
    }
}
Cephei::QL::Indexes::Inflation::CYYUKRPIr::!CYYUKRPIr ()
{
    if (_ppYYUKRPIr != NULL)
    {
	    delete _ppYYUKRPIr;
    }
}
QuantLib::YYUKRPIr& Cephei::QL::Indexes::Inflation::CYYUKRPIr::GetReference ()
{
    if (_ppYYUKRPIr == NULL) throw gcnew NativeNullException ();
	return **_ppYYUKRPIr;
}
boost::shared_ptr<QuantLib::YYUKRPIr>& Cephei::QL::Indexes::Inflation::CYYUKRPIr::GetShared ()
{
    if (_ppYYUKRPIr == NULL) throw gcnew NativeNullException ();
	return *_ppYYUKRPIr;
}
QuantLib::YYUKRPIr* Cephei::QL::Indexes::Inflation::CYYUKRPIr::GetPointer ()
{
    if (_ppYYUKRPIr == NULL) throw gcnew NativeNullException ();
	return &**_ppYYUKRPIr;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::YYUKRPIr>& Cephei::QL::Indexes::Inflation::CYYUKRPIr::GetHandle ()
{
	if (_phYYUKRPIr == NULL)
	{
		_phYYUKRPIr = new Handle<QuantLib::YYUKRPIr> (*_ppYYUKRPIr);
	}
	return *_phYYUKRPIr;
}
#endif
bool Cephei::QL::Indexes::Inflation::CYYUKRPIr::HasNative () 
{
	return (_ppYYUKRPIr != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Indexes::Inflation::IYYUKRPIr^ Cephei::QL::Indexes::Inflation::CYYUKRPIr_Factory::Create (Boolean interpolated, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Termstructures::IYoYInflationTermStructure^>^ ts)
{
    return gcnew CYYUKRPIr ( interpolated,  ts);
}
